/* include bsp */
#include "led.h"
#include "air32f10x.h"
/* include rtos */
#include "FreeRTOS.H"
#include "task.h"

TaskHandle_t test1Task_Handler;
#define TEST1_TASK_FUNCTION		test1Task
#define TEST1_TASK_NAME			"test1"
#define TEST1_TASK_STACK		50
#define TEST1_TASK_PRIORITY		1
#define TEST1_TASK_HANDLER		test1Task_Handler
void test1Task(void *pvParameters);

TaskHandle_t test2Task_Handler;
#define TEST2_TASK_FUNCTION		test2Task
#define TEST2_TASK_NAME			"test2"
#define TEST2_TASK_STACK		50
#define TEST2_TASK_PRIORITY		2
#define TEST2_TASK_HANDLER		test2Task_Handler
void test2Task(void *pvParameters);

TaskHandle_t test3Task_Handler;
#define TEST3_TASK_FUNCTION		test3Task
#define TEST3_TASK_NAME			"test3"
#define TEST3_TASK_STACK		50
#define TEST3_TASK_PRIORITY		3
#define TEST3_TASK_HANDLER		test3Task_Handler
void test3Task(void *pvParameters);

int main(void)
{

	/* initilize hardwares */
	LED_Init();

	taskENTER_CRITICAL();
	/* create task one */
	xTaskCreate((TaskFunction_t ) TEST1_TASK_FUNCTION,     
				(const char*    ) TEST1_TASK_NAME,   
				(uint16_t       ) TEST1_TASK_STACK,
				(void*          ) NULL,
				(UBaseType_t    ) TEST1_TASK_PRIORITY,
				(TaskHandle_t*  ) &TEST1_TASK_HANDLER);
	/* create task two */
	xTaskCreate((TaskFunction_t ) TEST2_TASK_FUNCTION,     
				(const char*    ) TEST2_TASK_NAME,   
				(uint16_t       ) TEST2_TASK_STACK,
				(void*          ) NULL,
				(UBaseType_t    ) TEST2_TASK_PRIORITY,
				(TaskHandle_t*  ) &TEST2_TASK_HANDLER);
	/* create task three */
	xTaskCreate((TaskFunction_t ) TEST3_TASK_FUNCTION,     
				(const char*    ) TEST3_TASK_NAME,   
				(uint16_t       ) TEST3_TASK_STACK,
				(void*          ) NULL,
				(UBaseType_t    ) TEST3_TASK_PRIORITY,
				(TaskHandle_t*  ) &TEST3_TASK_HANDLER);
	taskEXIT_CRITICAL();
	vTaskStartScheduler();
	
	return 0;
}

void test1Task(void *pvParameters)
{
	/* task one for test */
	while (1) {
		LED1_Toggle();
		vTaskDelay(500);
		LED1_Toggle();
		vTaskDelay(500);
	}
}

void test2Task(void *pvParameters)
{
	/* task two for test */
	LED2_Toggle();
	while (1) {
		LED2_Toggle();
		vTaskDelay(500);
		LED2_Toggle();
		vTaskDelay(500);
	}
}

void test3Task(void *pvParameters)
{
	/* task two for test */
	while (1) {
		LED3_Toggle();
		vTaskDelay(2000);
		LED3_Toggle();
		vTaskDelay(2000);
	}
}
